import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;

import javax.imageio.ImageIO;
import javax.swing.JFrame;


/**
 * 
 * @author Luke Brown
 *
 */
public class Menu extends JFrame implements MouseMotionListener,MouseListener,KeyListener{
	public BufferedImage textureBlue = getImage("blue.png");
	public BufferedImage textureEarth = getImage("earth.png");
	public BufferedImage textureGreen = getImage("green.png");
	public BufferedImage textureMarble = getImage("marble.png");
	public BufferedImage texturePaper = getImage("paper.png");
	public BufferedImage textureRed = getImage("red.png");
	public BufferedImage textureSun = getImage("sun.png");
	public BufferedImage textureTrippy = getImage("trippy.png");
	public BufferedImage textureTrippy2 = getImage("trippy2.png");
	public BufferedImage textureWood = getImage("wood.png");
	public BufferedImage textureYellow = getImage("yellow.png");
	public BufferedImage testSprite = getImage("testsprite.png");
	private Screen currentScreen;
	private Graphics g;
	private Graphics2D g2;
	private BufferedImage mainScreenImg;
	private Graphics2D graphicsMSI;
	
	/**
	 * Creates a new Menu of the specified width and height
	 * 
	 * @param width the width of the menu
	 * @param height the height of the menu
	 */
	public Menu(int width, int height){
		setBounds(0,0,width,height);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
        g = getGraphics();
        g2 = (Graphics2D)g;
        mainScreenImg = new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB);
        graphicsMSI = mainScreenImg.createGraphics();
        addMouseMotionListener(this);
        addMouseListener(this);
        addKeyListener(this);
        setResizable(false);
	}
	
	/**
	 * Creates a new Menu of the specified width and height and with an initial screen
	 * 
	 * @param width the width of the menu
	 * @param height the height of the menu
	 * @param initialScreen the initial screen for the menu to load up
	 */
	public Menu(int width, int height, Screen initialScreen){
		setBounds(0,0,width,height);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
        g = getGraphics();
        g2 = (Graphics2D)g;
        mainScreenImg = new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB);
        graphicsMSI = mainScreenImg.createGraphics();
        addMouseMotionListener(this);
        addMouseListener(this);
        addKeyListener(this);
        setResizable(false);
	}


	public void paint(){
		currentScreen.update();
		currentScreen.paint(graphicsMSI);
		this.g2.drawImage(mainScreenImg, null, 0, 0);
	}

	/**
	 * A method which can be used to get an Image as a BufferedImage
	 * 
	 * @param filename the string of the path of the object to load
	 * @return a BufferedImage version of the image being loaded
	 */
	public BufferedImage getImage(String filename){
		BufferedImage pic = null;
		try{
			pic=ImageIO.read(new File(filename));
		}catch(Exception e){
			System.out.println("Error Loading Texture: "+filename);
		}
		return pic;
	}

	
	
	//Mouse and Key listening methods
	
	@Override
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void mouseClicked(MouseEvent e) {
		
	}



	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void mouseReleased(MouseEvent e) {

		this.setCurrentScreen(this.currentScreen.mouseClicked(e.getX(), e.getY()));
		
	}



	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	
	//Getters and Setters
	

	



	/**
	 * @return the g
	 */
	public Graphics getG() {
		return g;
	}



	/**
	 * @param g the g to set
	 */
	public void setG(Graphics g) {
		this.g = g;
	}



	/**
	 * @return the g2
	 */
	public Graphics2D getG2() {
		return g2;
	}



	/**
	 * @param g2 the g2 to set
	 */
	public void setG2(Graphics2D g2) {
		this.g2 = g2;
	}



	/**
	 * @return the mainScreenImg
	 */
	public BufferedImage getMainScreenImg() {
		return mainScreenImg;
	}



	/**
	 * @param mainScreenImg the mainScreenImg to set
	 */
	public void setMainScreenImg(BufferedImage mainScreenImg) {
		this.mainScreenImg = mainScreenImg;
	}



	/**
	 * @return the graphicsMSI
	 */
	public Graphics2D getGraphicsMSI() {
		return graphicsMSI;
	}



	/**
	 * @param graphicsMSI the graphicsMSI to set
	 */
	public void setGraphicsMSI(Graphics2D graphicsMSI) {
		this.graphicsMSI = graphicsMSI;
	}

	/**
	 * @return the currentScreen
	 */
	public Screen getCurrentScreen() {
		return currentScreen;
	}

	/**
	 * @param currentScreen the currentScreen to set
	 */
	public void setCurrentScreen(Screen currentScreen) {
		this.currentScreen = currentScreen;
	}
}